package com.epfresh.supplier.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.TestItemEntity;
import com.epfresh.supplier.entity.TestReportEntity;

import java.util.List;

/**
 * author:duyongqiang
 * mail: duyongqiang09@126.com
 * date:2019/7/2
 * Description:
 */
public class TestReportRecyclerViewAdapter extends RecyclerView.Adapter<TestReportRecyclerViewAdapter.ViewHolder> {
    private Context context;
    private List<TestReportEntity> list;

    public TestReportRecyclerViewAdapter(Context context, List<TestReportEntity> list) {
        this.context = context;
        this.list = list;
    }

    public interface OnItemClickListener{
        void onItemClick(ViewHolder viewHolder, int position);
    }

    public interface OnClickListener{
        void onClick(View view, int position);
    }

    public interface BindData{
        void onBind(ViewHolder viewHolder, TestReportEntity testReportEntity, int position);
    }

    public OnItemClickListener onItemClickListener;
    public OnClickListener onClickListener;
    public BindData bindData;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener=onItemClickListener;
    }

    public void setOnClickListener(OnClickListener onClickListener){
        this.onClickListener=onClickListener;
    }

    public void setOnBindData(BindData bindData){
        this.bindData=bindData;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view= LayoutInflater.from(context).inflate(R.layout.test_report_item,viewGroup,false);
        ViewHolder viewHolder=new ViewHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int i) {
        if (viewHolder!=null){

            //给控件绑定数据设置回调
            bindData.onBind(viewHolder,list.get(i),i);


            //给Item项点击设置点击事件回调
//            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    onItemClickListener.onItemClick(viewHolder,i);
//                }
//            });

        }

    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        public ImageView iv_test_report;

        /**
         * 自定义ViewHolder的构造函数
         * @param itemView
         */
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv_test_report=itemView.findViewById(R.id.iv_test_report);

        }


    }

}
